package db

import (
	"GoMaestro/internal/conf"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"os"
)

func Init() {
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		conf.C.DB.MysqlUser,
		conf.C.DB.MysqlPassword,
		conf.C.DB.MysqlHost,
		conf.C.DB.MysqlPort,
		conf.C.DB.MysqlDatabasename)
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		log.Print(err)
		os.Exit(5)
	}
	conf.MysqlDataConnect = db
}
